package com.woniu.controller;

import com.woniu.entity.PageResult;
import com.woniu.entity.Result;
import com.woniu.pojo.Doctor;
import com.woniu.service.IDoctorService;
import com.woniu.vo.QuerySearchDoctorVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author doujiao
 * @since 2022-10-10
 */
@RestController
@RequestMapping("/doctor")
@Api(tags = "医生模块")
public class DoctorController extends BaseController{

    @Autowired
    private IDoctorService doctorService;

    /**
     * 分页搜索查找所有医生
     */
    @ApiOperation("分页搜索查找所有医生")
    @PostMapping("/search/{currentPage}/{pageSize}")
    public Result searchByPage(@PathVariable String currentPage, @PathVariable String pageSize,
                               @RequestBody QuerySearchDoctorVo searchDoctorVo){
       PageResult pageResult= doctorService.searchByPage(currentPage,pageSize,searchDoctorVo);
       return toDataResult(pageResult);
    }
    /**
     * 增加医生
     */
    @PostMapping
    @ApiOperation("增加医生")
    public Result add(@RequestBody Doctor doctor){
        boolean save = doctorService.save(doctor);
        return toResult(save);
    }

    /**
     * 修改医生
     */
    @PutMapping
    @ApiOperation("修改医生")
    public Result edit(@RequestBody Doctor doctor){
        boolean result = doctorService.updateById(doctor);
        return toResult(result);
    }
    /**
     * 根据id删除医生
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除医生")
    public Result removeById(@PathVariable String id){
        boolean result = doctorService.removeById(id);
        return toResult(result);
    }
}
